// component/processManageTable/processManageTable.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    list: {
      type: Array,
      value: []
    },
    allChecked: {
      type: Boolean,
      value: false
    },
    admin: {
      type: String,
      value: '0'
    }
    
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    onAllChange() {
      const arr = [...this.properties.list];
      let ids = [];
      arr.forEach(item => {
        if(this.properties.allChecked) {
          item.isCheckBox = false;
        }else {
          item.isCheckBox = true;
        }
        if(item.isCheckBox) ids.push(item.id);
      });
      this.triggerEvent("onAllChange", {
        allChecked: !this.properties.allChecked,
        list: arr,
        ids
      });
    },
    onCheckedBox(e) {
      const arr = [...this.properties.list];
      let flag = false;
      let ids = [];
      arr.forEach(item => {
        if(e.currentTarget.dataset.id == item.id) {
          item.isCheckBox = !item.isCheckBox;
        }
        if(!item.isCheckBox) flag = true;
        if(item.isCheckBox) ids.push(item.id);
      });
      this.triggerEvent("onAllChange", {
        allChecked: flag ? false : true,
        list: arr,
        ids
      });
    },
    delete(e) {
      const id = e.currentTarget.dataset.id;
      this.triggerEvent("deleteGetData", id);
    },
  }
})

